package com.itheima.mycollectiondemo;

import java.util.ArrayList;
import java.util.Iterator;

public class MyCollectionDemo6 {
    public static void main(String[] args) {
        Student s1 = new Student("张三",23);
        Student s2 = new Student("李思思",25);

        ArrayList<Student> students = new ArrayList<>();
        students.add(s1);
        students.add(s2);
        //迭代器循环
        Iterator<Student> it = students.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
        System.out.println("----------------------------------");
        //for增强型
        //此时student是for循环中定义的,students是ArrayList的变量名
        //for循环格式:for(集合/数组中元素的数据类型 变量名 : 集合/数组名) {}
                        //  Student            student   students
        for(Student student : students){
            System.out.println(student);
        }

    }

}
